

#import "Polygons.h"
#import "MyControl.h"

@implementation QuartzPolygonView

@synthesize drawingMode ,qq ,stroke;

-(void)setDrawingMode:(CGPathDrawingMode)mode
{
    NSLog(@"in mode");
	if(mode != drawingMode)
	{
        qq = 3;
        stroke = 1.0;
		drawingMode = mode;
		[self setNeedsDisplay];
	}
}

-(void)drawInContext:(CGContextRef)context
{
	
    // Drawing with a white stroke color
	CGContextSetRGBStrokeColor(context, 0.0, 0.0, 1.0, 1.0);
	// Drawing with a blue fill color
	CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
	// Draw them with a 2.0 stroke width so they are a bit more visible.
	CGContextSetLineWidth(context, stroke);
    
	CGPoint center;
    
	// Now add the hexagon to the current path
	
    
    center = CGPointMake(120.0, 150.0);//this is the coordinate of the polygon
	CGContextMoveToPoint(context, center.x, center.y + 80.0);
    for(int i = 1; i < qq; ++i)
	{
		
        CGFloat x = 80.0 * sinf(i * 2.0 * M_PI / qq);
		CGFloat y = 80.0 * cosf(i * 2.0 * M_PI / qq);
		CGContextAddLineToPoint(context, center.x + x, center.y + y);
	}
	// And close the subpath.
	CGContextClosePath(context);
	
	// Now draw the star & hexagon with the current drawing mode.
	CGContextDrawPath(context, kCGPathFillStroke);
}

@end
